package com.dh;

import org.elasticsearch.client.IndicesClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

public class ESApp {
    public static void createIndex(RestHighLevelClient client,String indexName) {
        CreateIndexRequest request = new CreateIndexRequest(indexName);
        try {
            CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
            boolean acknowledged = response.isAcknowledged();
            System.out.printf("index option status %s \n",acknowledged);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception{
        RestHighLevelClient client = ESTestClient.getClient();
        IndicesClient indices = client.indices();
        System.out.println(indices);

        createIndex(client,"dhindex2");

        ESTestClient.closeClient();

    }
}
